package com.controller;


import com.entity.pojo.SystemUser;
import com.entity.vo.FunctionUser;
import com.service.SystemFuncyionService;
import com.service.SystemUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/User")
public class UserController {
    //controller调service层
    @Autowired
    private SystemUserService systemUserService;
    @Autowired
    private SystemFuncyionService systemFuncyionService;
    @RequestMapping("/login")
    public String list(String userName, String userPwd, HttpSession session, Model model) {
        System.out.println("获取前端user:"+userName);
        SystemUser user = systemUserService.selectByPrimaryKey(userName, userPwd);
        if (user != null) {
            List<FunctionUser> list = systemFuncyionService.findByRoleID(user.getRoleId());
            session.setAttribute("list",list);
            session.setAttribute("msg",user.getUserName());
            session.setAttribute("userId",user.getUserId());
            return "main";
        }else {
            session.setAttribute("msg","账号或密码错误!");
            return "redirect:/index.jsp";
        }
    }
    @RequestMapping("/outlogin")
    public String outlogin(HttpSession session){
        //注销session
        session.invalidate();
        return "redirect:/index.jsp";
    }

}
